package com.facotry.controller;

import com.facotry.entity.ProduceWorkOrder;
import com.facotry.service.ProduceWorkOrderService;
import com.facotry.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * ------ 天道酬勤 -------
 *
 * @author ChenZihao
 * @date 2024/7/25
 * @desc --- 代码敲烂 月薪过万 ---
 */


@RestController
@RequestMapping("/produceWorkOrder")
public class ProduceWorkOrderController {

    @Autowired
    private ProduceWorkOrderService produceWorkOrderService;

    @GetMapping("/getList")
    public R findAll(@RequestParam HashMap<String,String> map){
        System.out.println("map = " + map);
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum, pageSize);
        List<ProduceWorkOrder> list = produceWorkOrderService.findAll(map);
        PageInfo<ProduceWorkOrder> pageInfo = new PageInfo<>(list);
       return R.ok(pageInfo);
    }


    @GetMapping("/addProduceWorkOrder")
    public R addProduceWorkOrder(ProduceWorkOrder produceWorkOrder){
        System.out.println("produceWorkOrder = " + produceWorkOrder);
       boolean isOk =  produceWorkOrderService.addProduceWorkOrder(produceWorkOrder);
        return R.ok(isOk);
    }


    @GetMapping("/delBatchWorkOrders")
    public R delBatchWorkOrders(@RequestParam List<String> ids){
        boolean isOk = produceWorkOrderService.delBatchWorkOrders(ids);

        return R.ok(isOk);
    }


    @GetMapping("/workOrderDown")
    public R workOrderDown(ProduceWorkOrder produceWorkOrder){
        boolean isOk = produceWorkOrderService.workOrderDown(produceWorkOrder);
        return R.ok(isOk);
    }

    @GetMapping("/workOrderStop")
    public R workOrderStop(ProduceWorkOrder produceWorkOrder){
        boolean isOk = produceWorkOrderService.workOrderStop(produceWorkOrder);
        return R.ok(isOk);
    }
    @GetMapping("/workOrderClose")
    public R workOrderClose(ProduceWorkOrder produceWorkOrder){
        boolean isOk = produceWorkOrderService.workOrderClose(produceWorkOrder);
        return R.ok(isOk);
    }

}
